
#ifndef CSharpUsing_h
#define CSharpUsing_h

// This struct uses internally in Riccsson.System library for the 'using' macro.
template<typename T> struct _struct_usingHolder
{
	T& _holder;
	char _m_isDone;

	_struct_usingHolder(T* holder)
		: _holder(*holder)
		, _m_isDone(0)
	{
	}

	_struct_usingHolder(T& holder)
		: _holder(holder)
		, _m_isDone(0)
	{
	}

	~_struct_usingHolder()
	{
		_holder->Dispose();
	}

	void _next()
	{
		_m_isDone++;
	}

	bool _isDone()
	{
		return _m_isDone == 1;
	}
};

// Using.
#define using(Type, VariableName, Initialization)																																\
	if(bool b_##VariableName = false)																																			\
		;																																										\
	else																																										\
		for(Type VariableName = Initialization; !b_##VariableName; b_##VariableName = true)																						\
			for(_struct_usingHolder<Type> _disposable_##VariableName(VariableName); _disposable_##VariableName._isDone() != 1; _disposable_##VariableName._next())

#endif